<include file="Public/head" />
<style type="text/css">
    .store_status{border: 1px solid #d2d2d2;color: #303030;display: block;float: left;height: 26px;line-height: 26px;text-align: center;width: 300px;}
    .storeService{resize:none;border:solid 1px #d2d2d2;width:300px;height: 50px;}
    .storeType{width:300px;border:solid 1px #d2d2d2;height: 28px; line-height: 28px; text-indent: 10px;font-family:"微软雅黑";background:#fff url(http://img1.isou365.cn/paimai/yunying/images/sanjiao.jpg) no-repeat 280px 6px;}
    .coordinate{width:200px;height: 30px; line-height: 30px;color:#fff; background:#20ab4f;border:none;border-radius: 5px;}
    #file_qrcode{width:310px; overflow: hidden;font-size: 300px;height: 30px; opacity:0;cursor: pointer; position: absolute;top:0;left:100px; z-index: 2;}
    .employee ul li .storeMap{width:300px;height: 28px; line-height: 28px;color:#fff; background: #20ab4f;border: none; position: absolute;top:0;left:110px ;z-index:1;cursor: pointer;}
    .employee ul li .mapBtn{width:90px; display: inline-block; background: #20ab4f;color:#fff; text-align: center;}
    .employee ul li .mapCode{resize:none;border:solid 1px #d2d2d2;width:290px;height: 100px;padding:5px;}
    #file_qrcode-queue{margin-top: 40px;text-align: center;}

</style>
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/ztree/jquery.ztree.core-3.5.js" type="text/javascript"></script>
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/ztree/jquery.ztree.exedit-3.5.js" type="text/javascript"></script>
<script src="{:get_style_cdnurl()}paimai/yunying/js/city.js" type="text/javascript"></script>
<script type="text/javascript">
    var setting = {
        data: {
            simpleData: {
                enable: true
            }
        },
        callback:{
            onClick: zTreeOnClick
        }
    };
    var zNodes =[
    <?php foreach($list as  $item):?>
    {id:<?php echo $item['id'];?>, pId:<?php echo $item['pid'];?>, name:"<?php echo $item['name'];?>",<?php echo $item['id']==1 ? "open: true" : '' ;?>},
    <?php endforeach;?>
    ];
    function zTreeOnClick( event, treeId, treeNode){
        var depart_id = treeNode.id;
        $("#depart_id").val(treeNode.id);
        $("#depart").val(treeNode.name);
        $(".zTreeDemoBackground").fadeOut();
        $(".arer-sheng").fadeOut();
        $(".arer-shi").fadeOut();
        $(".arer-qu").fadeOut();
    }
    $(document).ready(function(){
        $.fn.zTree.init($("#tree"), setting, zNodes);

        $("#depart").click(function(){
            $(".employee .zTreeDemoBackground").fadeToggle();
            $("#tree").show();
        })

        $("#depart").click(function(event){
            $(this).siblings("ul").fadeIn()
            $(this).parent().siblings("li").find("ul").fadeOut();
            $(".arer-sheng ul,.arer-shi ul,.arer-qu ul").fadeIn();
            $(".arer-sheng").fadeOut();
            $(".arer-shi").fadeOut();
            $(".arer-qu").fadeOut();
            event.stopPropagation();
        });

        $("body").click(function(event){
            $(".employee .menbox").fadeOut();
            $(".employee .zTreeDemoBackground").fadeOut();
            event.stopPropagation();
        })
        $(".zTreeDemoBackground").click(function(event){
            event.stopPropagation();
        })
    });
</script>
</head>
<body>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="nrgl.mdgl" />

    <form id="store_form" action="/StoreManage/add" method="post"  >
        <div class="mianR">
            <h3 class="cha"><if condition="$store['store_id'] gt 0">编辑<else/>新增</if>门店</h3>
            <div class="shangFrom shangFrom1 clearfix"></div>
            <div><input type="button" value="查询坐标（百度地图）" class="coordinate" onclick="window.open('http://api.map.baidu.com/lbsapi/getpoint/');"/></div>
            <div class="employee">
                <ul class="clearfix">
                    <li>
                        <span>*门店名称</span>
                        <input type="text"  name="store_name" value="{$store.store_name}"  placeholder="门店名称"/>
                    </li>
                    <li>
                        <span>*门店负责人</span>
                        <input type="text"  name="store_lead" value="{$store.store_lead}"  placeholder="门店负责人"/>
                    </li>
                    <li>
                        <span>*所在地区</span>												
                        <script>
                            var add = new AddressCom();
                        </script>
                    </li> 
                     <li>
                        <span>*负责人手机号</span>
                        <input type="text"  name="lead_mobile" value="{$store.lead_mobile}"  placeholder="负责人手机号"/>
                    </li>
                      <li>
                        <span>*详细地址</span>
                        <input type="text"  name="store_address" value="{$store.address}" placeholder="门店详细地址" />
                    </li>
                     <li>
                        <span>*负责人邮箱</span>
                        <input type="text"  name="lead_email" value="{$store.lead_email}"  placeholder="负责人邮箱"/>
                    </li>
                    <li>
                        <span>*门店电话</span>
                        <input type="text"  name="store_tel" value="{$store.store_tel}"  placeholder="门店电话"/>
                    </li>
<!--                    <li>
                        <span>状态</span>
                        <select name="store_status" class="store_status">
                            <if condition='$store.status eq 0'>
                            <option value="0" selected>正常</option>
                            <option value="1">禁用</option>
                            <else/>
                                <option value="0">正常</option>
                                <option value="1" selected>禁用</option>
                            </if>
                        </select>
                    </li>-->

                    <li>
                        <span>*门店类型</span>
                        <select name="type" class="storeType">
                            <option value="1" <if condition="$store['type'] eq 1">selected="selected"</if>>体验店</option>
                            <option value="2" <if condition="$store['type'] eq 2">selected="selected"</if>>社区门店</option>
                            <option value="3" <if condition="$store['type'] eq 3">selected="selected"</if>>交付店</option>
                        </select>
                    </li>

                    <li>
                        <span>服务范围</span>
                        <textarea cols="40" rows="3" name="service" class="storeService">{$store.service}</textarea>
                    </li>
                    <li>
                        <span>关联部门</span>
                        <input type="text" id="depart"  value="{$store.depart_name}"  placeholder="请选择关联部门" readonly>
                        <input type='hidden' id='depart_id' name="depart_id" value="{$store.depart_id}" />
                        <div class="zTreeDemoBackground left">
                            <ul id="tree" class="ztree"></ul>
                        </div>

                    </li>


                    <li>
                        <span>*坐标(X)</span>
                        <input type="text" name="pointer_x" value="{$store.pointer_x}">
                    </li>
                    <li>
                        <span><a class="mapBtn" href="http://api.map.baidu.com/lbsapi/creatmap/index.html" target="_blank" title="获取百度地图代码">百度地图代码</a></span>
                        <textarea name="script" class="mapCode">{$store.script}</textarea>
                    </li>
                    <li>
                        <span>*坐标(Y)</span>
                        <input type="text"  name="pointer_y" value="{$store.pointer_y}"/>
                    </li>

                    <li>
                        <span>地图二维码</span>
                        <input type="button" value="请选择文件" class="storeMap" readonly>
                        <input type="file" class="file_upload_style" id="file_qrcode" onclick="uploadPic('qrcode')">
                        <input type="hidden" name="qrcode" id="qrcode" value="{$store.qrcode}"/>
                        <div class="upload-img-box" style="margin-top: 40px; text-align: center;">
                            <div class="upload-pre-item">
                                <if condition="$store.qrcode neq ''">
                                    <img style="max-width: 400px;max-height: 400px;" src="{$store.qrcode}" />
                                </if>
                            </div>
                        </div>
                    </li>

                </ul>
            </div>
            <div class="yongBtn">
                <input type="hidden"  name="channel_id" value="{$store.channel_id}" />
                <input type="hidden"  name="store_id" value="{$store.store_id}" />
                <input type="button" value="确定" class="queding" />
                <input name="重置" type="reset" class="quxiao" onclick="history.go(-1);" value="取消" />
            </div>
        </div>
    </form>
</div>
<div class="clear"></div>
<script type="text/javascript" src="/Public/static/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript">
    window.onload=function(){
        $(".employee ul .zTreeDemoBackground ul li span").click(function(){

    var store_id = '{$store.store_id}';
            if($('.arer-sheng ul').css("display")=="block"){
                $(".arer-sheng ul,.arer-shi ul,.arer-qu ul").fadeOut();
            }else{
                $(".arer-sheng ul,.arer-shi ul,.arer-qu ul").fadeIn();
            }
       

        })
    }
    var store_id = '{$store.store_id}';
    if(store_id>0){
        add.set_init(["{$store.province}", "{$store.city}", "{$store.area}"]);//初始值
    }
    $(".queding").click(function(){
            var btn_obj = $(this);
            var post_data = $("#store_form").serialize();
            btn_obj.val("提交中...").attr("disabled", 'disabled');
            $.post("{:U('/StoreManage/add')}", post_data, function (data) {
                if (data.code != 200) {
                    shibai_alert(data.msg, 1500);
                    btn_obj.val("确定").removeAttr("disabled style");
                    return false;
                }
                btn_alert((store_id>0?'更新':'添加')+'成功', 1500, function () {
                    location.href = "{:U('StoreManage/index')}";
                });
            }, "json");
    })
</script>
<script type="text/javascript">
//        $(".file_upload_style").trigger("click");
        uploadPic('qrcode');
        function uploadPic(id) {
            /* 初始化上传插件 */
            $("#file_" + id).uploadify({
                "height": 30,
                "swf": "/Public/static/uploadify/uploadify.swf",
                "fileObjName": id,
                "buttonText": "上传图片",
                "uploader": "/StoreManage/upload_pic",
                "width": 300,
                'removeTimeout': 1,
                'fileTypeExts': '*.jpg; *.png; *.gif;',
                "onUploadSuccess": uploadCallBack,
//                'onFallback': function() {
//                    alert('未检测到兼容版本的Flash.');
//                }
            });
        }
        function uploadCallBack(file, data) {
            var data = eval("("+data+")");
            if(data.code==200){
                 var src = data.data;
                $('#qrcode').val(src);
                $('.upload-img-box').html('<div class="upload-pre-item"><img style="max-width: 400px;max-height: 400px;" src="' + src + '"/></div>');
            }else{
                alert(data.msg)
            }
        }
        </script>
<include file="Public/foot" />